 var table ,form ,laypage ,layer ,element ,laydate ,upload ,treetable ,colorpicker//时间组件
 $(function(){
    layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function () {
    	table = layui.table;
        form=layui.form;
        laypage = layui.laypage ;//分页
        layer = layui.layer ;//弹层
        element = layui.element; //元素操作
        laydate = layui.laydate; //时间组件 
        upload = layui.upload;
        dictPublicfun();
		table.render({
		    elem: '#tabledata',
		    height: $(window).height()-200,		   
		    text: {
			    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
			  },			
			method: 'post',  
			loading: true,
		    url: '/supplier/getList.do' ,//数据接口
		    headers: setHeader(),
		    parseData: function(res){
                return res.resultData;
            },
            response: {
                statusName: 'status', //规定数据状态的字段名称，默认：code
                statusCode: 200, //规定成功的状态码，默认：0
                msgName: 'hint', //规定状态信息的字段名称，默认：msg
                countName: 'total', //规定数据总数的字段名称，默认：count
                dataName: 'data' //规定数据列表的字段名称，默认：data
            },
		    page: true, //开启分页
		    cols: [[
	        	 {field: 'id', title: 'id', align:'left',hide:true,width:50},
 	        	 {field: 'xuhao', title: '序号',  align:'center', type:'numbers',width:50},
 	             {field: 'name', title: '名称',width:150},
 	             {field: 'remarks', title: '备注',width:200,align:'center'},
     	         {field: 'createTime', title: '创建时间', align:'center',width:200, 
	   			    	  templet: function(data){
	   				  			return changeTime(data.createTime)					        							        
	   				  		}  
   			      },
 	             {field: '', title: '操作', align:'center',width:200,fixed:'right',
 	            	 templet: function(data){
 							return '<div class="layui-btn-group">'+
 									   '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs DEPART DEPART_EDIT" lay-event="edit">编辑</a>'+
 	                                   '<a href="javascript:;" class="layui-btn layui-btn-xs DEPART DEPART_LOOK" lay-event="look">查看</a>'+        
 							           '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs DEPART DEPART_DEL" lay-event="del" >删除</a>'+	                             
 	                               '</div>'   
 						}	 
 	             }	     	            
 	         ]],
		    done: function (res) {
		    	 permissionFUN()//功能按钮权限
		    	 if(res.status!=200){
		    		if(res.status == 666){
		    			 TIMEOUT(); 
	  		        }else{
                	  $(".layui-none").text(res.resultMsg)
	  		        }  
                }
            }
		});	       
  	  //监听行工具事件
  	  table.on('tool(auth-table)', function(obj){
  	    var data = obj.data;
  	    if(obj.event === 'del'){
  		      layer.confirm('确认要删除该数据?', function(index){
  			    	//异步删除数据
	  		    	var requestData = {"id": data.id};
	          	  	$.ajax({
	      	           url: "/supplier/deleteSupplier.do",               //请求地址
	      	           type: "POST",              //请求类型
	      	           data:formatParam(requestData),              //请求数据
	      	           timeout: 200000,                //请求超时时间(毫秒)
	      	           headers: setHeader(),
	      	           success:function(res){         //请求成功
	      	        	   if(res.status == 200)
	      	  				{
		      	        		 layer.msg(res.resultMsg, {icon: res.icon},function(){
	      	    					 layer.closeAll();//关闭加载层
	      	    					table.reload("tabledata", {});
	      						}); 			
	      	  				}else{
	      	  					layer.msg(res.resultMsg, {icon: res.icon});
	      	  				}
	      	        	   form.render();      
	                    }
	                 })
	                 layer.close(index);//关闭确认框
	                 return false;
  			      }); 

  	    }else if (obj.event === 'look') {
	  	    	var num = obj.data;
			    var fullindex=layer.open({
			        type: 1,
			        area: ['690px', '420px'],
			        fix: false, //不固定
			        maxmin: true,
			        shadeClose: true,
			        shade:0.4, //遮罩层
			        title: ['供应商信息查看','background:#1E9FFF;color:#fff'],
			        content: $('#form_look')
			    });
			    $('#form_look').find("input ,select ,textarea").val("")
			    $('#form_look').find("input ,select ,textarea").attr("disabled",true)
			    var requestData = {"id": num.id};
          	  	$.ajax({
      	           url: "/supplier/getOneSupplier.do",               //请求地址
      	           type: "POST",              //请求类型
      	           data:formatParam(requestData),              //请求数据
      	           timeout: 200000,                //请求超时时间(毫秒)
      	           headers: setHeader(),
      	           success:function(res){         //请求成功
      	        	   if(res.status == 200) {
      	        		    var num=res.resultData;
	      		 		    $("#namelook").val(num.name);		    		   
	      		 		    $("#remarkslook").val(num.remarks);
	      		 		   form.render(); 				
      	  				}else{
      	  					layer.msg(res.resultMsg, {icon: res.icon});
      	  				}
      	  				      
                    }
                 })
        }else if(obj.event === 'edit'){ //编辑
        	var num = obj.data;
        	var fullindex=layer.open({
		        type: 2,
		        area: ['800px', '420px'],
		        fix: false, //不固定
		        maxmin: true,
		        shadeClose: true,
		        shade:0.4, //遮罩层
		        title: ['供应商编辑','background:#1E9FFF;color:#fff'],
		        content: "/res/page/supplier/supplier_form.html?id="+num.id+'&permissionId='+permissionId	
		    });			  	  		    
		    form.render();
	   }  	   
  	     form.render();
  	  });
  	// 查询按钮提交查询信息
      form.on('submit(queryData)', function(data){
	        // 组装查询条件
	        var reqData = getConditionValue();
	        // 重新加载表格数据
	        table.reload("tabledata", {
	             where: {"reqData" : JSON.stringify(reqData)}
		         ,page: {
		            curr: 1 //重新从第 1 页开始
		          }
	        });
	    });
   });
	
})
